/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkgUtil;

import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import javax.imageio.ImageIO;
import pkgMetodoPyramid.pkgSoporte.Constants;

/**
 *
 * @author Administrador
 */
public class UtilLayoutPantalla {

    public static void centrarEnPantallaJFrame(javax.swing.JFrame plla) {
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension tamVtna = kit.getScreenSize();
        int alto = tamVtna.height;
        int ancho = tamVtna.width;


        int fx = plla.getWidth() / 2;
        int fy = plla.getHeight() / 2;

        int px = ancho / 2;
        int py = alto / 2;

        plla.setLocation((px - fx), (py - fy));
    }

    public static void centrarEnPantallaJDialog(javax.swing.JDialog plla) {
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension tamVtna = kit.getScreenSize();
        int alto = tamVtna.height;
        int ancho = tamVtna.width;


        int fx = plla.getWidth() / 2;
        int fy = plla.getHeight() / 2;

        int px = ancho / 2;
        int py = alto / 2;

        plla.setLocation((px - fx), (py - fy));
    }

    public static void insertarIcono(javax.swing.JFrame plla, String pathIcon) {
        //Toolkit kit = Toolkit.getDefaultToolkit();
        UtilLayoutPantalla util=new UtilLayoutPantalla();
        Image img = util.getImage(pathIcon); //gif y jpeg
        plla.setIconImage(img);
    }
    
    private BufferedImage getImage(String pathIcon) {

        try {
            InputStream is = getClass().getResourceAsStream(pathIcon);
            BufferedImage buffImage = ImageIO.read(is);
            return buffImage;
        } catch (Exception ex) {
            return null;
        }
    }

    public static void mostrarPantalla(javax.swing.JDesktopPane desktopPane, javax.swing.JInternalFrame plla) {
        centrarEnDesktopPaneJInternalFrame(desktopPane,plla);
        plla.setClosable(true);//Que se pueda cerrar con la opcion de la barra de titulo
        plla.setIconifiable(true);//Que se pueda minimizar
        desktopPane.remove(plla);
        desktopPane.add(plla);
        plla.setVisible(true);
    }
    
    public static void mostrarPantalla(javax.swing.JDesktopPane desktopPane, 
                                       javax.swing.JInternalFrame plla,
                                       boolean closable,
                                       boolean maximizable,
                                       boolean iconifiable,
                                       boolean resizable, 
                                       boolean centrar) {
        if(centrar)
         centrarEnDesktopPaneJInternalFrame(desktopPane,plla);
        
        plla.setResizable(resizable);
        plla.setClosable(closable);//Que se pueda cerrar con la opcion de la barra de titulo
        plla.setMaximizable(maximizable);//Que se pueda maximizar
        plla.setIconifiable(iconifiable);//Que se pueda minimizar
        
        desktopPane.remove(plla);
        desktopPane.add(plla);
        plla.setVisible(true);
    }
    
    public static void centrarEnDesktopPaneJInternalFrame(javax.swing.JDesktopPane desktopPane,javax.swing.JInternalFrame plla) {
        Dimension tamVtna = desktopPane.getSize();
        int alto = tamVtna.height;
        int ancho = tamVtna.width;

        int fx = plla.getWidth() / 2;
        int fy = plla.getHeight() / 2;

        int px = ancho / 2;
        int py = alto / 2;

        plla.setLocation((px - fx), (py - fy));

    }
    
    public static void initWaiting(javax.swing.RootPaneContainer pllaParent) {
        pllaParent.getContentPane().setCursor(new Cursor(Cursor.WAIT_CURSOR));
    }

    public static void endWaiting(javax.swing.RootPaneContainer pllaParent) {
        pllaParent.getContentPane().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
